
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class AddContactValidationForm extends ActionForm{

	
		public String nom;
		
		public String prenom;
		
		public String email;
		
		public String adresse;
		
	
	//get and set methods
		
		
		public String getNom(){
		return nom;}
		
		public void setNom(String newnom){
		this.nom= newnom;}
		
		
		public String getPrenom(){
		return prenom;}
		
		public void setPrenom(String newprenom){
		this.prenom= newprenom;}
		
		
		public String getEmail(){
		return email;}
		
		public void setEmail(String newemail){
		this.email= newemail;}
		
		
		public String getAdresse(){
		return adresse;}
		
		public void setAdresse(String newadresse){
		this.adresse= newadresse;}
		
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
		HttpServletRequest request, HttpServletResponse response){
		String success = new String("success");
		String error = new String("error");
		String nom = (String) request.getAttribute("nom");
		String prenom = (String) request.getAttribute("prenom");
		String email = (String) request.getAttribute("email");
		String adresse = (String) request.getAttribute("adresse");
		return mapping.findForward(success);
	}
		
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if(getNom() == null || getNom().length() < 1){
			errors.add("nom", new ActionMessage("creation.fn.error.required"));
		}
		
		if(getPrenom() == null || getPrenom().length() < 1){
			errors.add("prenom", new ActionMessage("creation.fn.error.required"));
		}
		
		if(getEmail() == null || getEmail().length() < 1){
			errors.add("email", new ActionMessage("creation.fn.error.required"));
		}
		
		if(getAdresse() == null || getAdresse().length() < 1){
			errors.add("adresse", new ActionMessage("creation.fn.error.required"));
		}
		
		return errors;
	}
	
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.nom = null;
		this.prenom = null;
		this.email = null;
		this.adresse = null;
	}
	
}
	
	
	